package com.study.functioninterface;

import org.junit.Test;

import java.util.Comparator;
import java.util.stream.Stream;

public class ReferenceTest {
    /**
     * 1.方法引用
     */
    @Test
    public  void test1(){
        //3种情况:  object::InstanceMethod    Class::staticMethod   class::instanceMethod
        //前两种 等价于 (param...)->{ xxx(params...) }   第三种等价于(x,y)->{x.method(y)}
        MyFunctionInterface first =System.out::println;
        first.print("第一种");
        MyFunctionInterface second=String::new;
        second.print("2");
        MyFunctionInterface third =String::toString;
        third.print("33");
    }
    /**
     * 2.使用super 和this
     */
    @Test
    public  void test2(){
        Man man = new Man();
        man.print("33");
    }
    /**
     * 3.构造器引用
     */
    @Test
    public  void test3(){

    }

}
class People{
    void print(String s){
        System.out.println("好人~!!");
    }

}
class Man extends People{

    void print2(String s){
        System.out.println("第二个");
    }
    @Override
    void print(String s) {
        MyFunctionInterface method1 = super::print;
        method1.print(s);
        MyFunctionInterface  method2= this::print2;
        method2.print(s);
        System.out.println(s);
    }
}